﻿namespace Example.Creational
{
    using System;
    using System.Collections.Generic;

    using Example.Creational.Builder;

    using Xunit;

    /// <summary>
    /// Separate the construction of a complex object from its representation so that the same construction process can create different representations.
    /// </summary>
    public sealed class BuilderFacts
    {
        [Fact]
        public void calculator_result()
        {
            var values = new List<decimal>
                             {
                                 456, 
                                 -123
                             };

            var director = new ResultDirector
                               {
                                   Builder = new CalculatorResultBuilder()
                               };

            var result = director.Evaluate(values);

            Assert.Equal(333, result.Total);
            Assert.Equal("333", result.ToString());
        }

        [Fact]
        public void ledger_result()
        {
            var values = new List<decimal>
                             {
                                 456, 
                                 -123
                             };

            var director = new ResultDirector
                               {
                                   Builder = new LedgerResultBuilder()
                               };

            var result = director.Evaluate(values);

            Assert.Equal(333, result.Total);

            var expected =
                "456" + Environment.NewLine +
                "-123" + Environment.NewLine +
                "=333";

            Assert.Equal(expected, result.ToString());
        }
    }
}